//
//  SCRewardViewController.m
//  Mutal
//
//  Created by TonyStart on 16/10/28.
//  Copyright © 2016年 com.wx. All rights reserved.
//

#import "SCRewardViewController.h"
#import "SCRewardModeBtn.h"
#import "SCAlertView.h"

@interface SCRewardViewController ()
@property(nonatomic,strong)UITextField *wishPriceField;
@property(nonatomic,strong)UIView *inputView;
@property(nonatomic,strong)SCRewardModeBtn *weixinBtn;
@property(nonatomic,strong)SCRewardModeBtn *zhifubaoBtn;
@property(nonatomic,strong)SCRewardModeBtn *yueBtn;
@end
#define BUTTON_HEIGHT 40
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size
@implementation SCRewardViewController

-(UIView *)inputView{
    if (!_inputView) {
        _inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 74, [UIScreen mainScreen].bounds.size.width, 40)];
        _inputView.backgroundColor = [UIColor whiteColor];
        
        UILabel *wishLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 80, 20)];
        wishLabel.text = @"打赏金额";
        
        
        _wishPriceField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(wishLabel.frame)+2, 5, [UIScreen mainScreen].bounds.size.width - 80 - 35, 30)];
        _wishPriceField.keyboardType = UIKeyboardTypeNumberPad;
        _wishPriceField.textAlignment = NSTextAlignmentRight;
        _wishPriceField.placeholder = @"输入金额";
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_wishPriceField.frame)+2, 10, 20, 20)];
        label.text = @"元";
        
        [_inputView addSubview:wishLabel];
        [_inputView addSubview:_wishPriceField];
        [_inputView addSubview:label];
    }
    return _inputView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1];
    
    [self setupUI];
}


-(void)setupUI{
    [self.view addSubview:self.inputView];
    
    [self setupButtons];
}

-(void)setupButtons{
    _weixinBtn = [[SCRewardModeBtn alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.inputView.frame)+80, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-微信" title:@"微信支付"];
    _weixinBtn.tag = 1;
    [_weixinBtn addTarget:self action:@selector(rewardModeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _zhifubaoBtn = [[SCRewardModeBtn alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_weixinBtn.frame)+1, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-支付宝" title:@"支付宝支付"];
    _zhifubaoBtn.tag = 2;
    [_zhifubaoBtn addTarget:self action:@selector(rewardModeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    _yueBtn = [[SCRewardModeBtn alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_zhifubaoBtn.frame)+1, SCREEN_SIZE.width, BUTTON_HEIGHT) iconStr:@"icon-余额" title:@"余额支付"];
    _yueBtn.tag = 3;
    [_yueBtn addTarget:self action:@selector(rewardModeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *rewardBtn = [[UIButton alloc] initWithFrame:CGRectMake(50, CGRectGetMaxY(_yueBtn.frame)+50, SCREEN_SIZE.width - 100, BUTTON_HEIGHT)];
    rewardBtn.backgroundColor = [UIColor colorWithRed:81/255.0 green:200/255.0 blue:195/255.0 alpha:1];
    [rewardBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [rewardBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [rewardBtn setTitle:@"确认打赏" forState:UIControlStateNormal];
    [rewardBtn addTarget:self action:@selector(sureReward) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_weixinBtn];
    [self.view addSubview:_zhifubaoBtn];
    [self.view addSubview:_yueBtn];
    [self.view addSubview:rewardBtn];

}

-(void)sureReward{
    if ([_wishPriceField.text isEqualToString:@""] || [_wishPriceField.text doubleValue]<=0) {
        [SCAlertView alertViewWithTitle:@"金额不能为空且金额必须大于0"];
        return;
    }
    
    
}
-(void)rewardModeBtnClick:(SCRewardModeBtn*)sender{
    if (sender.tag == 1) {
        _weixinBtn.btnRightIcon.image = [UIImage imageNamed:@"icon-选中"];
        _zhifubaoBtn.btnRightIcon.image = nil;
        _yueBtn.btnRightIcon.image = nil;
    }else if (sender.tag == 2){
        _zhifubaoBtn.btnRightIcon.image = [UIImage imageNamed:@"icon-选中"];
        _weixinBtn.btnRightIcon.image = nil;
        _yueBtn.btnRightIcon.image = nil;
    }else if (sender.tag == 3){
        _yueBtn.btnRightIcon.image = [UIImage imageNamed:@"icon-选中"];
        _zhifubaoBtn.btnRightIcon.image = nil;
        _weixinBtn.btnRightIcon.image = nil;
    }
}
@end
